package com.itheima.health.config;

import com.itheima.health.job.CleanImgJob;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.text.ParseException;

/**
 * 定义任务描述和具体的执行时间
 */
@Configuration
public class QuartzConfig {
    @Bean
    public JobDetail clearImageJobDetail(){
        return JobBuilder.newJob(CleanImgJob.class)//PrintTimeJob我们的业务类
                .withIdentity("clearImageJobDetail")//可以给该JobDetail起一个id
                .storeDurably(true)
                .build();
    }
    @Bean
    public Trigger printTimeJobTrigger(@Qualifier("clearImageJobDetail") JobDetail jobDetail) throws ParseException {
        return TriggerBuilder.newTrigger()
                .forJob(jobDetail)//关联上述的JobDetail
                .withIdentity("clearImageJobTrigger")
                .withSchedule(CronScheduleBuilder.cronSchedule("10 0 4 1/1 * ?"))// 凌晨4点
                .build();
    }
}